<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.9.1"/>
<title>knet: 事件循环</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">knet
   &#160;<span id="projectnumber">1.4.5</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.9.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>首页</span></a></li>
      <li><a href="modules.html"><span>模块</span></a></li>
      <li><a href="annotated.html"><span>结构体</span></a></li>
      <li><a href="files.html"><span>文件</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="搜索" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">函数</a>  </div>
  <div class="headertitle">
<div class="title">事件循环</div>  </div>
</div><!--header-->
<div class="contents">

<p>网络事件循环  
<a href="#details">更多...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
函数</h2></td></tr>
<tr class="memitem:ga2e4181ebe9c1769be90bb8dc0e5cdffe"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga2e4181ebe9c1769be90bb8dc0e5cdffe.html#ga2e4181ebe9c1769be90bb8dc0e5cdffe">knet_loop_create</a> ()</td></tr>
<tr class="memdesc:ga2e4181ebe9c1769be90bb8dc0e5cdffe"><td class="mdescLeft">&#160;</td><td class="mdescRight">创建一个事件循环  <a href="a00117_ga2e4181ebe9c1769be90bb8dc0e5cdffe.html#ga2e4181ebe9c1769be90bb8dc0e5cdffe">更多...</a><br /></td></tr>
<tr class="separator:ga2e4181ebe9c1769be90bb8dc0e5cdffe"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga390ea3161f935d0d3a411df8752d8b9f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga390ea3161f935d0d3a411df8752d8b9f.html#ga390ea3161f935d0d3a411df8752d8b9f">knet_loop_destroy</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:ga390ea3161f935d0d3a411df8752d8b9f"><td class="mdescLeft">&#160;</td><td class="mdescRight">销毁事件循环 事件循环内的所有管道也会被销毁  <a href="a00117_ga390ea3161f935d0d3a411df8752d8b9f.html#ga390ea3161f935d0d3a411df8752d8b9f">更多...</a><br /></td></tr>
<tr class="separator:ga390ea3161f935d0d3a411df8752d8b9f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac1f9a4848c06c2a6a2723d7b991b4394"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00056_a3b7e82599367eade261456f60ebe2cd9.html#a3b7e82599367eade261456f60ebe2cd9">kchannel_ref_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_gac1f9a4848c06c2a6a2723d7b991b4394.html#gac1f9a4848c06c2a6a2723d7b991b4394">knet_loop_create_channel</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop, uint32_t max_send_list_len, uint32_t recv_ring_len)</td></tr>
<tr class="memdesc:gac1f9a4848c06c2a6a2723d7b991b4394"><td class="mdescLeft">&#160;</td><td class="mdescRight">创建管道  <a href="a00117_gac1f9a4848c06c2a6a2723d7b991b4394.html#gac1f9a4848c06c2a6a2723d7b991b4394">更多...</a><br /></td></tr>
<tr class="separator:gac1f9a4848c06c2a6a2723d7b991b4394"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaddfd5a2709d0c26ada8a2dd3fd6a5b62"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00056_a3b7e82599367eade261456f60ebe2cd9.html#a3b7e82599367eade261456f60ebe2cd9">kchannel_ref_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_gaddfd5a2709d0c26ada8a2dd3fd6a5b62.html#gaddfd5a2709d0c26ada8a2dd3fd6a5b62">knet_loop_create_channel_exist_socket_fd</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop, <a class="el" href="a00056_a0d9e0afbf02fb6ed6c5b1415dce51b05.html#a0d9e0afbf02fb6ed6c5b1415dce51b05">socket_t</a> socket_fd, uint32_t max_send_list_len, uint32_t recv_ring_len)</td></tr>
<tr class="memdesc:gaddfd5a2709d0c26ada8a2dd3fd6a5b62"><td class="mdescLeft">&#160;</td><td class="mdescRight">使用已存在的套接字创建管道  <a href="a00117_gaddfd5a2709d0c26ada8a2dd3fd6a5b62.html#gaddfd5a2709d0c26ada8a2dd3fd6a5b62">更多...</a><br /></td></tr>
<tr class="separator:gaddfd5a2709d0c26ada8a2dd3fd6a5b62"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga37ab03493fb1ed037815f2cd951d762a"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga37ab03493fb1ed037815f2cd951d762a.html#ga37ab03493fb1ed037815f2cd951d762a">knet_loop_run_once</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:ga37ab03493fb1ed037815f2cd951d762a"><td class="mdescLeft">&#160;</td><td class="mdescRight">运行一次事件循环 kloop_t不是线程安全的，不能在多个线程内同时对同一个kloop_t实例调用knet_loop_run_once  <a href="a00117_ga37ab03493fb1ed037815f2cd951d762a.html#ga37ab03493fb1ed037815f2cd951d762a">更多...</a><br /></td></tr>
<tr class="separator:ga37ab03493fb1ed037815f2cd951d762a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaaf104ae1337c32415bd1aa8df545ae31"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_gaaf104ae1337c32415bd1aa8df545ae31.html#gaaf104ae1337c32415bd1aa8df545ae31">knet_loop_run</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:gaaf104ae1337c32415bd1aa8df545ae31"><td class="mdescLeft">&#160;</td><td class="mdescRight">运行事件循环直到调用knet_loop_exit() kloop_t不是线程安全的，不能在多个线程内同时对同一个kloop_t实例调用knet_loop_run  <a href="a00117_gaaf104ae1337c32415bd1aa8df545ae31.html#gaaf104ae1337c32415bd1aa8df545ae31">更多...</a><br /></td></tr>
<tr class="separator:gaaf104ae1337c32415bd1aa8df545ae31"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9e04a2d06c79405f444aa53a26eedd90"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga9e04a2d06c79405f444aa53a26eedd90.html#ga9e04a2d06c79405f444aa53a26eedd90">knet_loop_exit</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:ga9e04a2d06c79405f444aa53a26eedd90"><td class="mdescLeft">&#160;</td><td class="mdescRight">退出函数knet_loop_run()  <a href="a00117_ga9e04a2d06c79405f444aa53a26eedd90.html#ga9e04a2d06c79405f444aa53a26eedd90">更多...</a><br /></td></tr>
<tr class="separator:ga9e04a2d06c79405f444aa53a26eedd90"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga1eca6d310350a4545182666db28fb91f"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga1eca6d310350a4545182666db28fb91f.html#ga1eca6d310350a4545182666db28fb91f">knet_loop_get_active_channel_count</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:ga1eca6d310350a4545182666db28fb91f"><td class="mdescLeft">&#160;</td><td class="mdescRight">获取活跃管道数量  <a href="a00117_ga1eca6d310350a4545182666db28fb91f.html#ga1eca6d310350a4545182666db28fb91f">更多...</a><br /></td></tr>
<tr class="separator:ga1eca6d310350a4545182666db28fb91f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8a8c7aee4eed09d50062a5f464cdba7a"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_ga8a8c7aee4eed09d50062a5f464cdba7a.html#ga8a8c7aee4eed09d50062a5f464cdba7a">knet_loop_get_close_channel_count</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:ga8a8c7aee4eed09d50062a5f464cdba7a"><td class="mdescLeft">&#160;</td><td class="mdescRight">获取已关闭管道数量  <a href="a00117_ga8a8c7aee4eed09d50062a5f464cdba7a.html#ga8a8c7aee4eed09d50062a5f464cdba7a">更多...</a><br /></td></tr>
<tr class="separator:ga8a8c7aee4eed09d50062a5f464cdba7a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf1239ea65307d7dc588175c45947437b"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_gaf1239ea65307d7dc588175c45947437b.html#gaf1239ea65307d7dc588175c45947437b">knet_loop_set_data</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop, void *data)</td></tr>
<tr class="memdesc:gaf1239ea65307d7dc588175c45947437b"><td class="mdescLeft">&#160;</td><td class="mdescRight">设置用户数据指针  <a href="a00117_gaf1239ea65307d7dc588175c45947437b.html#gaf1239ea65307d7dc588175c45947437b">更多...</a><br /></td></tr>
<tr class="separator:gaf1239ea65307d7dc588175c45947437b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gafc6a946f7c7fd4fb0508ac0f88969da1"><td class="memItemLeft" align="right" valign="top"><a class="el" href="a00056_ab75a5c23099a6118c469ed160b277f28.html#ab75a5c23099a6118c469ed160b277f28">kloop_profile_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="a00117_gafc6a946f7c7fd4fb0508ac0f88969da1.html#gafc6a946f7c7fd4fb0508ac0f88969da1">knet_loop_get_profile</a> (<a class="el" href="a00056_a97fc76209a58362019f1ded9169e397f.html#a97fc76209a58362019f1ded9169e397f">kloop_t</a> *loop)</td></tr>
<tr class="memdesc:gafc6a946f7c7fd4fb0508ac0f88969da1"><td class="mdescLeft">&#160;</td><td class="mdescRight">取得统计器  <a href="a00117_gafc6a946f7c7fd4fb0508ac0f88969da1.html#gafc6a946f7c7fd4fb0508ac0f88969da1">更多...</a><br /></td></tr>
<tr class="separator:gafc6a946f7c7fd4fb0508ac0f88969da1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">详细描述</h2>
<p>网络事件循环 </p>
<pre>
网络事件API，作为各个不同操作系统网络选取器的包装，屏蔽了不同平台的具体实现，
为你提供统一的调用接口.</pre><pre>管道引用kchannel_ref_t通过调用knet_loop_create_channel和knet_loop_create_channel_exist_socket_fd
创建，knet_loop_run将启动事件循环并等待调用knet_loop_exit退出，你可以手动调用knet_loop_run_once运行一次事件
循环自己控制循环的调用频率.</pre><pre>每个kloop_t内都维护了活跃管道和已关闭(未销毁)管道的双向链表，可以通过knet_loop_get_active_channel_count
和knet_loop_get_close_channel_count来取得具体数量.</pre><pre>在创建管道时，要注意两个重要的配置参数：</pre><pre>1. max_send_list_len 发送链表最大元素个数
2. recv_ring_len     接受缓冲区最大长度</pre><pre>通常向管道内发送数据(stream_push_系列)，管道会尝试直接发送，并不缓存要发送的数据，如果因为某种原因
导致不能直接发送，数据会被缓存在发送链表内等待合适的时机发送，如果发送链表的长度达到上限，管道会被关闭.
同样，接受缓冲区会从套接字内将数据读取出来，如果你一直不从kstream_t内取数据，那么早晚会被写满，管道也
会被关闭.</pre><pre></pre> </div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
生成于 2015年 七月 27日 星期一 14:33:20 , 为 knet使用  &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.9.1
</small></address>
</body>
</html>
